package com.eva.framework.config;

import com.eva.framework.config.enums.ApiModeEnum;
import com.eva.framework.config.enums.EnvEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

@Data
@Schema(description = "应用配置")
@Configuration
@ConfigurationProperties(prefix = "app", ignoreInvalidFields = true)
public class AppProperties {

    @Schema(description = "应用ID")
    private String id;

    @Schema(description = "启动模式")
    private ApiModeEnum mode;

    @Schema(description = "启动环境")
    private EnvEnum env;

    @Schema(description = "项目版本")
    private String version;

    @Schema(description = "超级管理员角色编码")
    private String superAdminRole;

    @Schema(description = "本地文件存储路径")
    private String localFileDirectory;

    /**
     * 判断是否为生产环境
     *
     * @return boolean
     */
    public boolean isProductionEnv () {
        return EnvEnum.production.equals(env);
    }

    /**
     * 判断是否为测试模式，当前测试模式下完成以下事项
     * - 不校验验证码
     *
     * @return boolean
     */
    public boolean isTestingMode () {
        // 生产环境视为false
        if (EnvEnum.production.equals(env)) {
            return Boolean.FALSE;
        }
        return ApiModeEnum.testing.equals(mode);
    }
}
